package cn.yeoman.flowcontrol.configurable.impl;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import cn.yeoman.flowcontrol.configurable.OutputService;
import cn.yeoman.flowcontrol.model.Notice;
import cn.yeoman.flowcontrol.util.Topic;

@Service("outputService")
public class OutputServiceImpl implements OutputService {

	private static List<Notice> notices = null;
	
	static{
		notices = new LinkedList<Notice>();
	}
	
	@Override
	public boolean notice(String relatedNo, Topic topic) {
		boolean flag = false;
		if(StringUtils.isNotBlank(relatedNo) && topic != null){
			Notice notice = new Notice(relatedNo, topic);
			flag = push(notice);
			System.out.println(notice);
		}
		// TODO Auto-generated method stub
		return flag;
	}
	
	private boolean push(Notice notice){
		return notices.add(notice);
	}
	
	@Override
	public int getNoticesSize(){
		return notices.size();
	}
	
	@Override
	public List<Notice> getNotices() {
		return notices;
	}

	@Override
	public Notice give(Notice notice){
		return notices.remove(notice) ? notice : null;
	}
}
